/**
 * All rights Reserved, Designed By Yuan Mei Tech.
 * Copyright (C), 2001-2012, Yuan.Mei
 * This program is protected by copyright laws.
 * @Title:  StockDogPreferActivity.java   
 * @Package com.yuanmei.stockdog   
 * @Description:    TODO(��һ�仰�������ļ���ʲô)   
 * @author: jkp2k@163.com     
 * @date:   2013-6-6 ����11:05:19   
 * @version V1.0
 */
package com.yuanmei.stockeyes.activities;

//import android.app.AlarmManager;
//import android.content.Context;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.util.Log;

import com.yuanmei.stockeyes.artifacts.GlobalSettings;
import com.yuanmei.stockeyes.artifacts.Constants;

import com.yuanmei.stockeyes.R;


public class PrefersActivity extends PreferenceActivity implements Preference.OnPreferenceChangeListener 
{
	public static final String LOG_TAG = "JKP_PrefersActivity";
	
	private CheckBoxPreference OnlyWifiChartPref;
	private CheckBoxPreference SmartWatchPref;
	private ListPreference     RefreshIntervalPref;

	@SuppressWarnings("deprecation")
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
	    super.onCreate(savedInstanceState);
 
		addPreferencesFromResource(R.xml.preference); 
		OnlyWifiChartPref   = (CheckBoxPreference) findPreference("onlyWifiChart"); 
		SmartWatchPref      = (CheckBoxPreference) findPreference("smartWatch"); 
		RefreshIntervalPref = (ListPreference) findPreference("refresh_interval_list"); 
		OnlyWifiChartPref.setOnPreferenceChangeListener(this); 
		RefreshIntervalPref.setOnPreferenceChangeListener(this); 
	}

    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,  
            Preference preference) {  
        //Log.i(LOG_TAG, "onPreferenceTreeClick----->"+preference.getKey());  

        if (preference.getKey().equals("version_check")) {
            //UpdateAgent.forceUpdate(this);
            return true;
        }
        
        /*
        else if (preference.getKey().equals("feed_back")) {
            FeedbackAgent agent = new FeedbackAgent(this);
            agent.startFeedbackActivity();
            return true;
        }
        */

        return false;  
    }
    
    public boolean onPreferenceChange(Preference preference, Object objValue) {
        if (preference == OnlyWifiChartPref){  
            boolean isChecked;
            try {
                isChecked = Boolean.valueOf(String.valueOf(objValue)).booleanValue();
                GlobalSettings.sbIsOnlyWifiDownloadChart = isChecked;
            } catch (Exception e) {
                Log.w(LOG_TAG,"Get OnlyWifiChartPref Occur Exception:" + e.getMessage());
            }
        } else if (preference == SmartWatchPref){
            boolean isChecked;
            try {
                isChecked = Boolean.valueOf(String.valueOf(objValue)).booleanValue();
                GlobalSettings.sbIsOnSmartWatch = isChecked;
            } catch (Exception e) {
                Log.w(LOG_TAG,"Get SmartWatchPref Occur Exception:" + e.getMessage());
            }
        } else if (preference == RefreshIntervalPref) {
            int iValue;
            try {
                iValue = Integer.valueOf(String.valueOf(objValue)).intValue();
                GlobalSettings.slSettingRefreshInterval = iValue * Constants.MINUTES_TO_MILLISECONDS;
            } catch (Exception e) {
                Log.w(LOG_TAG,"Get RefreshIntervalPref Occur Exception:" + e.getMessage());
            }
        } 
        return true;
    }  
}
